package com.example.houtai.controller;



import com.baomidou.mybatisplus.extension.service.IService;
import com.example.houtai.config.Logger;
import com.example.houtai.entity.SysMenu;
import com.example.houtai.service.ISysMenuService;
import com.github.pagehelper.PageInfo;

import com.org.dto.MenuDto;
import com.org.vo.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 菜单管理 前端控制器
 * </p>
 *
 * @author 龚梦
 * @since 2021-03-22
 */
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    //满亨炜


    @Autowired
    private ISysMenuService sysMenuService;

    @Logger("菜单列表")
    @RequestMapping("list")
    public ResultEntity list(){
        List<SysMenu> list=sysMenuService.selectMenu();
        return ResultEntity.ok("200","查询成功",list);
    }
    @RequestMapping("save")
    public ResultEntity save(@RequestBody MenuDto menuDto){
        SysMenu menu=new SysMenu();
        BeanUtils.copyProperties(menuDto,menu);
        sysMenuService.save(menu);
        return ResultEntity.ok("添加成功");
    }
    @RequestMapping("update")
    public ResultEntity update(@RequestBody MenuDto menuDto){
        SysMenu menu=new SysMenu();
        BeanUtils.copyProperties(menuDto,menu);
        menu.setMenuId(menu.getMenuId());
        sysMenuService.updateById(menu);
        return ResultEntity.ok("修改成功");
    }
    @RequestMapping("delete")
    public ResultEntity delete(@RequestParam ("ids")Integer[]ids){
        for (Integer id : ids) {
            System.out.println(id);
        }
        sysMenuService.removeByIds(Arrays.asList(ids));
        return ResultEntity.ok("删除成功");
    }

    @RequestMapping("rolemenuList")
    public ResultEntity list(@RequestParam("token")String token){
        System.out.println(token);
        return ResultEntity.ok("200","success",sysMenuService.rolemenuList(token));
    }
}